<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of gradingClass
 *
 * @author nathaniel.stevens.ad
 */
class gradingClass {

    //put your code here
    public $categoryArray; //2d array index 0 = category name, index 1 = value (scores), index 2 = count (num grades)

    function __construct() {
        $arrayCategories = getGradingCategoryArray();
        $this->categoryArray = array();
        //$this->$categoryCountArray = array();
        for ($i = 0; $i < sizeof($arrayCategories); $i++) {
            //create an array for each type
            $tempArray = array($arrayCategories[$i], "0", "0");
            array_push($this->categoryArray, $tempArray);
        }
    }

    function addGrade($catName, $score) {
        $index = $this->getCategoryIndex($catName);
        $this->categoryArray[$index][1] += $score;
        $this->categoryArray[$index][2]++;
    }

    function getAverage($catName) {
        $index = $this->getCategoryIndex($catName);
        $totalScore = $this->categoryArray[$index][1];
        $numScores = $this->categoryArray[$index][2];
        if(is_nan($numScores) || strcmp($numScores, "0")===0){
            return "N/A";
        }
        else{
           return round($totalScore/$numScores, 2); 
        }
    }

    function getCategoryIndex($catName) {
        for ($i = 0; $i < sizeof($this->categoryArray); $i++) {
            if (strcmp($this->categoryArray[$i][0], $catName) === 0) {
                return $i;
            }
        }
    }

}

?>
